package com.zzyq.pc.web.configure.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zzyq.pc.common.plugin.db.PageView;
import com.zzyq.pc.web.configure.mapper.DepartMapper;
import com.zzyq.pc.web.configure.model.Depart;
import com.zzyq.pc.web.configure.service.IDepartService;

@Service
public class DepartServiceImpl implements IDepartService {
    @Autowired
    DepartMapper departMapper;

    @Override
    public List<Depart> selectList(PageView pageView, Depart depart) {
        Map<String, Object> map = new HashMap<>();
        if (pageView != null) {
            map.put("paging", pageView);
        }
        map.put("departName", depart.getDepartName());
        map.put("departId", depart.getDepartId());
        map.put("companyId", depart.getCompanyId());
        return departMapper.selectList(map);
    }

    @Override
    public Depart selectById(Integer id) {
        if (id == null) {
            return null;
        }
        return departMapper.selectById(id);
    }

    @Override
    public List<Depart> selectSameList(Depart depart) {
        Map<String, Object> map = new HashMap<>();
        map.put("departName", depart.getDepartName());
        map.put("companyId", depart.getCompanyId());
        map.put("departId", depart.getDepartId());
        return departMapper.selectSameList(map);
    }

    @Override
    public boolean add(Depart depart) {
        depart.setIsDelete(0);
        return departMapper.add(depart) > 0;
    }

    @Override
    public boolean update(Depart depart) {
        return departMapper.update(depart) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        return departMapper.delete(id) > 0;
    }
}
